#!/usr/bin/env python 
# -*- coding: utf-8 -*-
# @Time    : 2023/5/4 17:54
# @Author  : Junzhao
# @File    : 增001.py
# @Software: PyCharm
import pymysql

# 链接MySQL
conn = pymysql.connect(host="127.0.0.1", port=3306, user='root', password="", charset='utf8', db='unicom')
# cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)
cursor = conn.cursor()

# 发送指令
# cursor.execute("insert into admin(username,password,mobile) values('junzhao','qwerty','15533736000')")

# 千万不要用字符串格式化做SQL语句拼接，有安全隐患SQL注入：可以这样
# sql = "insert into admin(username,password,mobile) values(%s,%s,%s)"
# cursor.execute(sql,['QAQ','qweeqw123321','19199191123'])

# 还可以：
sql = "insert into admin(username,password,mobile) values(%(n1)s,%(n2)s,%(n3)s)"
cursor.execute(sql, {"n1": "bab", "n2": "123qwe123qwe", "n3": "99991111999"})
conn.commit()

# 关闭连接
cursor.close()
conn.close()
